#include "GameServer.h"
#include "json.hpp"

GameServer::GameServer()
{
    server = std::make_shared<TcpServer>("0.0.0.0", 11111);
    server->onMessage = [](const ConnectionPtr &ptr, std::string &message) {
        json root = json::parse(message);
        std::string method = root["Method"];
        json body = root["Body"];
        int ret = Router::Call(method, body);
        root["Body"] = std::to_string(ret);
        ptr->Send(root.dump().data(), root.dump().size());
    };
}

void GameServer::Run()
{
    server->Run();
}